package com.jxauaia.contest.service.impl;

import com.jxauaia.contest.mapper.ContestDetailMapper;
import com.jxauaia.contest.mapper.ContestMapper;
import com.jxauaia.contest.model.entity.Contest;
import com.jxauaia.contest.model.entity.ContestDetail;
import com.jxauaia.contest.model.vo.ContestDetailVO;
import com.jxauaia.contest.service.ContestDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ContestDetailServiceImpl implements ContestDetailService {

    @Autowired
    private ContestDetailMapper contestDetailMapper;
    
    @Autowired
    private ContestMapper contestMapper;

    @Override
    public ContestDetailVO getById(Long id) {
        // 获取比赛详情
        ContestDetail contestDetail = contestDetailMapper.getById(id);
        if (contestDetail == null) {
            return null;
        }
        
        // 获取比赛基本信息
        Contest contest = contestMapper.findById(contestDetail.getId().intValue());
        if (contest == null) {
            return null;
        }
        
        // 组装VO
        ContestDetailVO vo = new ContestDetailVO();
        BeanUtils.copyProperties(contest, vo);
        BeanUtils.copyProperties(contestDetail, vo);
        
        return vo;
    }
}
